package com.作业.Day19;


/**
 * 需求：使用两个线程打印1到100的数字，实现轮着交互打印的效果。
 * 	线程1：1
 * 	线程2：2
 * 	线程1：3
 * 	线程2：4
 *
 */
public class Test6 {
    public static void main(String[] args) {
        MyThread5 myThread5 = new MyThread5();
        new Thread(myThread5,"线程1").start();
        new Thread(myThread5,"线程2").start();
    }
}
class MyThread5 implements Runnable{
    private int num = 0;
    @Override
    public void run() {
        while ( true){
            synchronized (this){
                notify();
            if( num <100){
                num++;
                System.out.println(Thread.currentThread().getName() + ":" + num);
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            else{
                notify();
                break;
            }


            }
        }

    }
}